package com.ssh;


public class CanPlaceFlowers_605 {
	public boolean canPlaceFlowers(int[] flowerbed, int n) {
		int t = 0, x = 0;
        if (flowerbed.length == 1 && flowerbed[0] == 0) {
        	x++;
        }
        for (int i = 0; i < flowerbed.length; i++) {
        	if (flowerbed[i] == 0) {
        		t++;
                if (t == 2 && (i == 1 || i == flowerbed.length-1)) {
                    x++;
                    t=1;
                }
        		if (t == 3) {
        			x++;
        			t = 1;
        		}
        	}else {
        		t = 0;
        	}
        }
        return x>=n;
    }
	
	
}
